#include "pch.h"
#include "CRectTrackerEx.h"

CRectTrackerEx::CRectTrackerEx()
{
}

void CRectTrackerEx::Draw(CDC* pDC, CPen* pPen, CBrush* pBrush) const
{
	if (m_nStyle & CRectTracker::dottedLine || m_nStyle & CRectTracker::solidLine)//如果是画虚线或者画实线
	{
		CRect rect = m_rect;
		rect.NormalizeRect();//规范化矩形
		CPen* pOldPen = pDC->SelectObject(pPen);
		CBrush* pOldBrush = pDC->SelectObject(pBrush);
		pDC->SetROP2(R2_COPYPEN);//设置绘图模式
		pDC->Rectangle(rect);//画矩形
		//获取画笔的颜色
		LOGPEN logpen;
		pPen->GetLogPen(&logpen);
		COLORREF color = logpen.lopnColor;
		//画8个点
		if (m_nStyle & CRectTracker::resizeInside || m_nStyle & CRectTracker::resizeOutside)//如果是画内部点或者画外部点
		{
			UINT mask = GetHandleMask();//获取点的掩码
			for (int i = 0; i < 8; i++)
			{
				if (mask & (1 << i))//如果第i个点存在
				{
					CRect handleRect;
					GetHandleRect(i, &handleRect);//获取第i个点的矩形
					pDC->FillSolidRect(handleRect, color);//填充矩形
				}

			}
		}
		pDC->SelectObject(pOldPen);
		pDC->SelectObject(pOldBrush);
	}
}
